<?php
	class Text {
	
		function textile($text){
			$search_array = array(
				"/\s\*([^\s].*?[^\s])\*[\s\.,]/",
				"/\s\_([^\s].*?[^\s])\_[\s\.,]/",
				"/\s\/([^\s].*?[^\s])\/[\s\.,]/",
				"/\s\\[mail\]([^\s].*?[^\s])\[\/mail][\s\.,]/",
				"/-([^\s].*?)[\r\n]/",
				"[\r\n]"
			);
			$replace_array = array(
				" <b>$1</b> ",
				" <u>$1</u> ",
				" <i>$1</i> ",
				" TOTOTOTOTOT ",
				"<li>$1</li>",
				"<br>"
			);
			return preg_replace($search_array,$replace_array,$text);
		}
		
		function nodesc($text){
			$search_array = array(
			"/\<h3\>/",
			"/\<\/h3\>/",
			"/\<br\>/",
			);
			$replace_array = array("");
			return preg_replace($search_array,$replace_array,$text);
		}
		
		function noh3($text){
			$search_array = array(
			"(\<h3\>)",
			"(\<br\>)",
			"(\<\/h3\>)",
			"(\<\/h3\>\<br\>)",
			);
			$replace_array = array("");
			return preg_replace($search_array,$replace_array,$text);
		}
		
		function textile1234512345($text){
			
			$search_array = array(
			"/\s\*([^\s].*?[^\s])\*[\s\.,]/",
			"/\s\_([^\s].*?[^\s])\_[\s\.,]/",
			"/\s\/([^\s].*?[^\s])\/[\s\.,]/",
			"/(#[A-Fa-f0-9]{6}|green|red|blue)\|(.*?)\|/",
			//TITULO (h1 - h2 - ...)
			"/h(\d{1})\.(.*?)\n/",
			//link
			"/\[([^\s].*?[^\s])\]\(([^\s].*?[^\s])\)/",
			//insertar imagen
			"/img\(([^\s].*?[^\s])\)/",
			//Lista
			"/-([^\s].*?)[\r\n]/",
			"/\(:\)/",
			"/\((::)\)/",
			"/\((#:)\)/",
			"/\((#::)\)/",
			//"/[^.\<\/li\>\n](\<li\>.*?\<\/li\>)[\n]?[^.\<li\>]/",
			//Descarga de documento A MEDIAS!
			"/\s(.*)(.doc|.pdf|.xls)/",
			//"/(\<li\>.*\<\/li\>)[^\<li\>]/"//\((.*?[^\s].doc|.pdf|.xls[^\s])\)
			"/[^\<(o|u)l\>](\r)/"
			);
			$replace_array = array(
			" <b>$1</b> ",
			" <u>$1</u> ",
			" <i>$1</i> ",
			"<font color=\"$1\">$2</font>","<h$1>$2</h$1>",
			"<a href=\"$2\">$1</a>",
			"<img src=\"$1\" alt=\"No se pudo cargar la imagen\">",
			"<li>$1</li>",
			"<ul>",
			"</ul>",
			"<ol>",
			"</ol>",
			"$1 - $2",
			"<br>");//"<a href=\"$1\"><img src=icon$2.gif></img></a>"
			$search_array = array(
			"/\/([^\s].*?[^\s])\//",
			"/h(\d{1})\.(.*?)\n/",
			"/\*([^\s].*?[^\s])\* /",
			"/\_([^\s].*?[^\s])\_/",
			"[\r\n]"
			);
			$replace_array = array(
			"<i>$1</i>",
			"<h$1>$2</h$1>",
			"<strong>$1</strong>",
			"<u>$1</u>",
			"<br/>"
			);
			return preg_replace($search_array,$replace_array,$text);
		}
		
		function remove_textile($text){
			$search_array = array(
			"/\s\*([^\s].*?[^\s])\*[\s\.,]/",
			"/\s\_([^\s].*?[^\s])\_[\s\.,]/",
			"/\s\/([^\s].*?[^\s])\/[\s\.,]/",
			"/(#[A-Fa-f0-9]{6}|green|red|blue)\|(.*?)\|/",
			"/h(\d{1})\.(.*?)\n/",
			"/\[([^\s].*?[^\s])\]\(([^\s].*?[^\s])\)/",
			"/img\(([^\s].*?[^\s])\)/",
			"(\n)"
			);
			$replace_array = array(" $1 "," $1 ", " $1 ","$2","$2",
								   "$1","[IMG]"," ");
			return preg_replace($search_array,$replace_array,$text);
		}
		
		function resume($text, $length,$use_textile=false){
			if($use_textile){
				$text = Text::textile($text);
			}else{
				$text = Text::remove_textile($text);
			}
			return (strlen($text)<$length) ? $text : substr($text, 0, strrpos (substr($text, 0, $length), " "))." &#8230;";
		}
		
		
		
	}

?>